package com.zhangdi.mgsync.core.thread;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/**
 * @author zhangdi
 * @version 1.0
 * @date 2022.2.16 15:46
 */
public class BatchSendTimeoutScheduleder {
    static BatchSendTimeoutScheduleder _this = new BatchSendTimeoutScheduleder();
    public static BatchSendTimeoutScheduleder get(){
        return _this;
    }

    ScheduledExecutorService pool;
    int corePoolSize = 16;
    public BatchSendTimeoutScheduleder() {
        MineThreadFactory threadFactory = new MineThreadFactory();
            threadFactory.setThreadNamePrefix("WatcherScheduledPool-");
        pool = Executors.newScheduledThreadPool(corePoolSize, threadFactory);
    }

    public synchronized ScheduledFuture<?> scheduleWithFixedDelay(Runnable worker, long delay, long period){
        return pool.scheduleWithFixedDelay(worker, delay, period, TimeUnit.MILLISECONDS);
    }

    public synchronized ScheduledFuture<?> scheduleAtFixedRate(Runnable worker, long delay, long period){
        return pool.scheduleAtFixedRate(worker, delay, period, TimeUnit.MILLISECONDS);
    }

    public void shutdown(){
        pool.shutdown();
    }
}
